#pragma once
#include <fstream>

namespace 
{
	std::string now()
	{
		std::stringstream _out;
		SYSTEMTIME now; 
		::GetSystemTime(&now);
		_out << now.wDay <<"."<< now.wMonth<<"."<<now.wYear<<":"<<now.wHour <<":"<<now.wMinute <<":"<<now.wSecond <<":"<<now.wMilliseconds << " ";
		return _out.str();
	}
};

class CLogger
{
public:
	CLogger( const char* iName )
	{
		Open(iName);
	}

	CLogger( const std::string& iName)
	{
		Open( iName.c_str() );
	}

	~CLogger()
	{
		m_log.close();
	}

	void CLogger::WriteString( const std::string& iString )
	{
		m_log << now() << iString << std::endl;
	}
protected:
	CLogger();
	CLogger(const CLogger&);
	const CLogger& operator=(const CLogger&);

	void Open( const char* iName )
	{
		m_log.open(iName, std::ios_base::app);
		if ( !m_log.is_open() )
			throw std::exception("cant open file");
	}
	std::ofstream m_log;

};

void Trace(const char* iLocation, const std::string& iMessage)
{
	#ifdef _DEBUG
	try
	{
		std::cout << "\n";
		std::cout << now() << " (";
		std::cout << iLocation << ") ";
		std::cout << iMessage;
		std::cout << "\n";
	}
	catch(...)
	{}
	#endif
}